package y23.Oct;


import java.util.concurrent.CountDownLatch;

class MyThread implements Runnable {
    private String threadName;
    private CountDownLatch currentLatch;
    private CountDownLatch nextLatch;
    public MyThread(String threadName, CountDownLatch currentLatch, CountDownLatch nextLatch) {
        this.threadName = threadName;
        this.currentLatch = currentLatch;
        this.nextLatch = nextLatch;
    }
    @Override
    public void run() {
        try {
            currentLatch.await();
            System.out.print(threadName);
            nextLatch.countDown();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

public class Test10 {
    public static void main(String[] args){
        CountDownLatch latchA = new CountDownLatch(1);
        CountDownLatch latchB = new CountDownLatch(1);
        CountDownLatch latchC = new CountDownLatch(1);
        Thread threadA = new Thread(new MyThread("a", latchC, latchA));
        Thread threadB = new Thread(new MyThread("b", latchB, latchC));
        Thread threadC = new Thread(new MyThread("c", latchA, latchB));

        threadC.start();
        threadB.start();
        threadA.start();
        latchA.countDown();
    }
}
